// ignore_for_file: unrelated_type_equality_checks
import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:yt_devops/model/info_item.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';

class AlarmModel {
  /// 告警ID
  int? id;

  /// 告警设备ID
  int? alarmDeviceId;

  /// 告警等级
  AlarmStatusGradeType? level;

  /// 告警名称
  String? name;

  /// 设备名称
  String? deviceName;

  /// 站点名称
  String? siteName;

  /// 告警内容
  String? content;

  /// 告警时间
  String? alarmTime;

  /// 告警状态，是否已处理(清除) 0产生 1清除
  AlarmStatusType? status;

  /// 修复时间
  String? recoveryTime;

  /// 是否确认
  AlarmConformStatusType? isConfirm;

  /// 确定时间
  String? confirmTime;
  /// 消除类型
  String? recoveryByName;
  /// 消除类型
  int? recoveryBy;
  /// 页数
  int? pageNum;

  /// 每页分页数
  int? pageSize;
  ///是否是历史告警
  bool? isHistory;
  AlarmModel({
    this.id,
    this.alarmDeviceId,
    this.level,
    this.name,
    this.deviceName,
    this.siteName,
    this.content,
    this.alarmTime,
    this.status,
    this.recoveryTime,
    this.isConfirm,
    this.recoveryByName,
    this.recoveryBy,
    this.confirmTime,
    this.pageNum,
    this.pageSize,
    this.isHistory,
  });

  factory AlarmModel.fromJson(Map<String, dynamic> json) => AlarmModel(
        id: json['id'],
        alarmDeviceId: json['alarmDeviceId'],
        level: $enumDecodeNullable($AlarmStatusGradeTypeEnumMap, json['level']),
        name: json['name'],
        deviceName: json['deviceName'],
        siteName: json['siteName'],
        content: json['content'],
        alarmTime: json['alarmTime'],
        status: $enumDecodeNullable($AlarmStatusTypeEnumMap, json['status']),
        recoveryTime: json['recoveryTime'],
        isConfirm: $enumDecodeNullable(
            $AlarmConformStatusTypeEnumMap, json['isConfirm']),
        confirmTime: json['confirmTime'],
        recoveryBy: json['recoveryBy'],
        recoveryByName: json['recoveryByName'],
        pageNum: json['pageNum'],
        pageSize: json['pageSize'],
      );

  List<InfoItem> get infoLists {
    return [
      InfoItem('${ResKey.siteName.tr}: ', siteName?.toString() ?? ''),
      InfoItem('${ResKey.alarmStatus.tr}: ', status!.label),
      InfoItem('${ResKey.deviceName.tr}: ', deviceName?.toString() ?? ''),
      InfoItem('${ResKey.generationTime.tr}: ', alarmTime?.toString() ?? ''),
    ];
  }
}

class AlarmListRequestParams {
  /// 告警名称
  String? alarmName;

  /// 告警时间开始时间
  String? startTime;

  /// 告警时间结束时间
  String? endTime;

  /// 站点id集合
  List<num>? siteIds;

  /// 设备id
  num? deviceId;

  /// 告警级别集合：info 提示 warn 次要 alarm 重要 error 严重
  List<String>? levels;

  /// 是否确认 是否确认:0-否 1-是
  int? isConfirm;

  /// 是否已处理(清除) 0未处理 1已处理
  int? status;
  ///历史告警恢复类型 0 为自动 1为手动
  int? recoverType;
  /// 当前页
  int current;

  /// 条数
  int pageSize;

  AlarmListRequestParams({
    this.alarmName = "",
    this.startTime = "",
    this.endTime = "",
    this.siteIds,
    this.deviceId,
    this.levels,
    this.isConfirm,
    this.status,
    this.recoverType,
    this.current = 1,
    this.pageSize = 10,
  });
}
